﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;

namespace Test
{
    /// <summary>
    /// 测试运行CMD的代码(勿改动).txt
    /// </summary>
    class TestCmdRun
    {
        public static string Cmd(string[] cmd)
        {
            Process p = new Process();
            p.StartInfo.FileName = "cmd.exe";
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardInput = true;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardError = true;
            p.StartInfo.CreateNoWindow = false;
            p.StartInfo.Arguments = @"/k ""D:\Program Files\Microsoft Visual Studio 10.0\VC\vcvarsall.bat"" x86";
            p.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
            p.StartInfo.WorkingDirectory = @"D:\Program Files\Microsoft Visual Studio 10.0\VC";
            p.Start();
            p.StandardInput.AutoFlush = true;
            for (int i = 0; i < cmd.Length; i++)
            {
                p.StandardInput.WriteLine(cmd[i].ToString());
            }
            p.StandardInput.WriteLine("exit");
            string strRst = p.StandardOutput.ReadToEnd();
            Console.Write(strRst);
            p.WaitForExit();
            p.Close();
            return strRst;
        }
    }
}
